home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / listSymbols / syms < prev   
Encoding:
Text File  |  1994-08-02  |  1.5 KB  |  66 lines

  1. #!/bin/sh
  2. #
  3. #    syms - list symbols of a specified type in an object or archive
  4. #
  5. #    Michael Gold, Silicon Graphics Computer Systems, June 1994
  6. #
  7. #    Given one or more objects and a section, syms lists all symbols 
  8. #    from that section for each input object.  The optional section 
  9. #    should be the letter from the Berkeley format nm(1) output.  The 
  10. #    default is 'T', which corresponds to External Text, unless the 
  11. #    script is invoked as "undef", in which case the default is 'U' 
  12. #    (External undefined).
  13. #
  14. #    If any named object is not found, the script searched for a
  15. #    corresponding shared object or archive in /usr/lib.  For 
  16. #    instance, "syms Xm" will search for ./Xm, /usr/lib/libXm.so,
  17. #    and /usr/lib/libXm.a until one is found.
  18. #
  19. #    All sections listed in nm(1) are supported.
  20. #
  21.  
  22. libdir=/usr/lib
  23. field=T
  24. cmd=`basename $0`
  25.  
  26. usage() {
  27.     echo "usage: $cmd [-NTtDdBbAaUGgSsRrCEVIbXPFo] file1 file2 ..."
  28.     exit 1
  29. }
  30.  
  31. if [ $# = 0 ]; then
  32.     usage
  33. fi
  34.  
  35. if [ "$cmd" = "undef" ]; then
  36.     field=U
  37. fi
  38.  
  39. while getopts NTtDdBbAaUGgSsRrCEVIbXPFo c; do
  40.     case $c in
  41.     N|T|t|D|d|B|b|A|a|U|G|g|S|s|R|r|C|E|V|I|b|X|P|F|o) field=$c;;
  42.     \?) usage;;
  43.     esac
  44. done
  45. shift `expr $OPTIND - 1`
  46.  
  47. for i in $*; do
  48.     if [ -f "$i" ]; then
  49.     file=$i
  50.     elif [ -f $libdir/lib$i.so ]; then
  51.     file=$libdir/lib$i.so
  52.     elif [ -f $libdir/lib$i.a ]; then
  53.     file=$libdir/lib$i.a
  54.     else
  55.     echo "$i not found"
  56.     file=""
  57.     fi
  58.  
  59.     if [ -n "$file" ]; then
  60.     nm -Bo $file \
  61.     | nawk -v field=$field '{ if ($3 == field) print $1 "\t" $4 " " $5 }'\
  62.     | sort
  63.     fi
  64. done
  65.  
  66.